<center>

<button onclick="$('#giftbox > tbody > tr.giftboxtree').each(function(i,e) { $(e).find('select').val($(e).hasClass('mastered')?'sell':'place').change();}); "
	>Place all unmastered and sell all mastered trees</button>
<br>
<br>

<?php
global $icons;
$vAllTrees = AFT_MakeTreeDB('gb');		
$treesInGB = 0;
foreach ($vAllTrees as $vATr) {
	if ($vATr['cntGB']>0) $treesInGB += $vATr['cntGB'];
}
if ($treesInGB == 0) $treesInGB = "No";
$s = $treesInGB == 1 ? "":"s";
?>

<table class="grid sortable" id="giftbox">
	<caption><?=$treesInGB?> Tree<?=$s?> in giftbox</caption>
	<thead>
		<tr>
			<th width="60">Image</th>
			<th>Name</th>
			<th>Mastery</th>
			<th>Release</th>
			<th>Coins</th>
			<th>Cocos</th>
			<th>Jade</th>
			<th>Count</th>
			<th>Action</th>
		</tr>
	</thead>
	<tbody>

<?php

foreach ($vAllTrees as $vATr) {
	if ($vATr['cntGB']>0) {
		$class = $vATr['mastery'] >= 1?"mastered":"";
		echo "<tr class=\"giftboxtree $class\"  tree=\"{$vATr['code']}\">";
		echo AFT_tr($vATr,array('icon','name','mastery','release','coins','cocos','jade','countGB'));
?>
		<td class="colorme" count="<?=$vATr['cntGB']?>"><?=$vATr['cntGB']?>
			<img class="icon<?=$vATr['actionGB']=="sell"?" on":""?>" src="<?=$icons['sell'.($vATr['actionGB']=="sell"?"":"Off")]?>" title="sell" action="actionGB">
			<img class="icon<?=$vATr['actionGB']=="place"?" on":""?>" src="<?=$icons['place'.($vATr['actionGB']=="place"?"":"Off")]?>" title="place" action="actionGB">
			<br>
			Keep:&nbsp;<input maxlength="6" name="tree-<?= urlencode($vATr['code'])?>-actionGBcnt" size="3" type="text" value="<?=$vATr['actionGBcnt']?>" class="saveConf" >
		</td>
<?php
/*		echo "<tr><td colspan=\"9\"><pre>";
		print_r($vATr);
		echo "</pre></td></tr>";
*/
		echo '</tr>';
	}
}
?>
	</tbody>
	<tfoot>
		<tr>
			<th>&nbsp;</th>
			<th>Total</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
			<th><?=$treesInGB?></th>
			<th>&nbsp;</th>
		</tr>
	</tfoot>
</table>
</center>
